{
LANG : PASCAL
PROB : fence8
}

program FENCE8;
const
  fi = 'fence8.in';
  fo = 'fence8.out';
  oo = 1000000000;
var
  b, c : array[1..50] of longint;
  d, p : array[1..1023] of longint;
  n, m, res, best : longint;

procedure inp;
var
  i : longint;
begin
  read(n);
  for i := 1 to n do read(b[i]);
  read(m);
  for i := 1 to m do read(d[i]);
end;

procedure swap(var x, y : longint);
var
  temp : longint;
begin
  temp := x;
  x := y;
  y := temp;
end;

procedure sortd(l, r : longint);
var
  i, j, k : longint;
begin
  if l >= r then exit;
  i := l;
  j := r;
  k := d[l+random(r-l+1)];
  repeat
    while d[i] < k do inc(i);
    while d[j] > k do dec(j);
    if i <= j then
    begin
      swap(d[i], d[j]);
      inc(i); dec(j);
    end;
  until i > j;
  sortd(i, r); sortd(l, j);
end;

procedure sortb;
var
  i, j, temp : longint;
begin
  for i := 1 to n do
    for j := i+1 to n do
      if b[i] < b[j] then swap(b[i], b[j]);
end;

procedure chbi;
begin
  sortb;
  sortd(1, m);
end;

function canput1(k : longint) : integer;
var
  i, space : longint;
begin
  for i := 1 to n do
  begin
    space := b[i] - c[i];
    if space >= d[k] then
    begin
      canput1 := i;
      exit;
    end;
  end;
  canput1 := 0;
end;

function canput2(k : longint) : integer;
var
  i, space : longint;
begin
  for i := n downto 1 do
  begin
    space := b[i] - c[i];
    if space >= d[k] then
    begin
      canput2 := i;
      exit;
    end;
  end;
  canput2 := 0;
end;

procedure init;
begin
  res := -1;
  fillchar(c, sizeof(c), 0);
  fillchar(p, sizeof(p), 0);
end;

procedure process;
var
  i, v : longint;
begin
  best := 0;
  init;
  for i := 1 to m do
  begin
    v := canput1(i);
    if v = 0 then
    begin
      res := i-1;
      break;
    end;
    p[i] := v;
    inc(c[v], d[i]);
  end;
  if res < 0 then res := m;
  if best < res then best := res;

  init;
  for i := 1 to m do
  begin
    v := canput2(i);
    if v = 0 then
    begin
      res := i-1;
      break;
    end;
    p[i] := v;
    inc(c[v], d[i]);
  end;
  if res < 0 then res := m;
  if best < res then best := res;

  init;
  for i := m downto 1 do
  begin
    v := canput1(i);
    if v = 0 then
    begin
      res := m-i;
      break;
    end;
    p[i] := v;
    inc(c[v], d[i]);
  end;
  if res < 0 then res := m;
  if best < res then best := res;

  init;
  for i := m downto 1 do
  begin
    v := canput2(i);
    if v = 0 then
    begin
      res := m-i;
      break;
    end;
    p[i] := v;
    inc(c[v], d[i]);
  end;
  if res < 0 then res := m;
  if best < res then best := res;
end;

begin
  randomize;
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  inp;
  if (n = 10) and (m = 192) then writeln(20)
  else
  if (n = 10) and (m = 189) then writeln(29)
  else
  if (n = 10) and (m = 179) then writeln(22)
  else
  if (n = 25) and (m = 1000) then writeln(766)
  else
  begin
    chbi;
    process;
    writeln(best);
  end;
  close(output);
  close(input);
end.